package thread01;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ProducterConsumerDemo {

	public static void main(String[] args) {
		
		Storage storage = new Storage();
		
		ExecutorService service = Executors.newCachedThreadPool(); // 创建线程池
		
		for (int i = 0; i < 5; i++) {
			service.submit(new Producter(storage));
		}
		
		for (int i = 0; i < 5; i++) {
			service.submit(new Consumer(storage));
		}
		
		// main 线程可能无法关闭ExecutorService建立的线程，所以需要手动关闭。这样当main线程退出时，这些线程才能退出
		service.shutdown();
	
	}
	
}
